﻿using System;
using Kaleida.ServiceMonitor.Model;
using NUnit.Framework;

namespace Kaleida.UnitTests.Model
{
    [TestFixture]
    public class CodePlexWebVersionCheckTests
    {
        [Test]
        public void TestCanReadVersion()
        {
            const string html = "blah blah @@@0.9.0.44@@@blah blah ";
            Assert.AreEqual("0.9.0.44", WebVersionCheck.ExtractVersionFromHtmlPage(html).ToString());
        }

        [Test, ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Couldn't extract latest version from https://www.rightcalc.com/blog/servicemon/version-check/ page. Unexpected format")]
        public void TestExceptionIsThrownIfUnexpectedPageFormat()
        {
            WebVersionCheck.ExtractVersionFromHtmlPage("@@0.9.0.44@@");
        }

        [Test, ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Couldn't extract latest version from https://www.rightcalc.com/blog/servicemon/version-check/ page. Unexpected format")]
        public void TestExceptionIsThrownIfUnexpectedVersionFormat()
        {
            WebVersionCheck.ExtractVersionFromHtmlPage("@@@0.90.44@@@");
        }
    }
}
